package com.qf.java2207.no3_teamproject_springboot_01.service.impl;
//须知少时凌云志，曾许人间第一流


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2207.no3_teamproject_springboot_01.mapper.SecurityPersonMapper;
import com.qf.java2207.no3_teamproject_springboot_01.pojo.SecurityPerson;
import com.qf.java2207.no3_teamproject_springboot_01.service.SecurityPersonService;
import com.qf.java2207.no3_teamproject_springboot_01.vo.LayuiPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SecurityPersonServiceImpl implements SecurityPersonService {
    @Autowired
    private SecurityPersonMapper securityPersonMapper;


    @Override
    public LayuiPageVo<SecurityPerson> securityPersonPageData(Map<String, Object> params) {
        // mybatis 的 分页插件
        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");
        PageHelper.startPage(page,limit);

        List<SecurityPerson> securityPersons = securityPersonMapper.selectByParams(params);

        // mybatis 的 分页数据结构
        PageInfo<SecurityPerson> securityPersonPageInfo = new PageInfo<>(securityPersons);
        //把mybatis 的 分页数据 封装到  layui 的分页数据结构中

        LayuiPageVo<SecurityPerson> securityPersonLayuiPageVo = new LayuiPageVo<>();
        securityPersonLayuiPageVo.setCode(0);  // layui 默认 0 是正确的状态码
        securityPersonLayuiPageVo.setMsg("分页列表数据"); // 提示信息
        securityPersonLayuiPageVo.setCount(securityPersonPageInfo.getTotal()); // 总记录数
        securityPersonLayuiPageVo.setData(securityPersonPageInfo.getList());  // 分页的列表数据
        return securityPersonLayuiPageVo;
    }

//    @Override
//    public List<SecurityPerson> securityPersonsList() {
//        return securityPersonMapper.selectByExample(null);
//    }


    @Override
    public int deleteSecurityPerson(Integer id) {
        return securityPersonMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateSecurityPerson(SecurityPerson securityPerson) {

        int i = securityPersonMapper.updateByPrimaryKeySelective(securityPerson);

        return i;
    }

    @Override
    public int addSecurityPerson(SecurityPerson securityPerson) {
        int i = securityPersonMapper.insertSelective(securityPerson);
        return i;
    }

}
